package com.lap.framework.validate.annotation;

import com.lap.framework.validate.annotation.Dict.List;
import com.lap.framework.validate.validator.DictValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 *
 *
 * <pre>
 * 数字字典校验注解
 * </pre>
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 * @see DictValidator
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(List.class)
@Documented
@Constraint(validatedBy = {DictValidator.class})
public @interface Dict {
  /**
   * 字典编码
   *
   * @return 字典编码
   */
  String code() default "";

  /**
   * 错误提示编码
   *
   * @return 错误提示编码
   */
  String message() default "{framework.dict.invalid}";

  /**
   * 分组
   *
   * @return 分组类型
   */
  Class<?>[] groups() default {};

  /**
   * payLoad
   *
   * @return 类型
   */
  Class<? extends Payload>[] payload() default {};

  /**
   * Defines several {@link Dict} annotations on the same element.
   *
   * <p>{@link com.lap.framework.validate.annotation.Dict}
   */
  @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
  @Retention(RUNTIME)
  @Documented
  @interface List {
    Dict[] value();
  }
}
